<?php

class Meeting extends FMIS_Controller 
{

	public function __construct() {
		parent::__construct();
        $this->load->database();
        $this->load->model('meeting/FMIS_Meeting');
        $this->load->model('faculty_meeting_status_model');
        $this->load->model('faculty_profile_model');
	}

    public function view()
    {
        $table = $this->FMIS_Meeting->get_statusDesc();
        $profiles = $this->faculty_profile_model->getAll();
        /*$meetings = $this->FMIS_Meeting->getAll();
        $meetings = $this->faculty_meeting_status_model->getStatusToArray($meetings);
        $meetings = $this->faculty_profile_model->getProfileToArray($meetings);
    	*/
        $meetings = $this->FMIS_Meeting->getAllMeetings_Peek();
        $data = array(
           'page_title'  => 'Meeting',
            'tbl' => $table,
            'profiles' => $profiles,
            'meetings' => $meetings
        );
    	$this->setup_view('meeting/view', $data);
    }

    public function viewmeeting($id)
    {
        $this->load->model('FMIS_Meeting');
        $meetingDetails = $this->FMIS_Meeting->getMeetingDetails($id);
        $meetingAttendees = $this->FMIS_Meeting->getMeetingAttendees($id);
        $this->setup_view('meeting/meeting-details-view', array(
            'page_title'  => $meetingDetails['MeetingName'],
            'details' => $meetingDetails,
            'attendees' => $meetingAttendees
        ));
    }

    public function record()
    {
        $recorder_id = $this->session->userdata('user_id'); //recorder_id
        $name = $this->input->post('input_name');
        $date = $this->input->post('input_date'); //date
        $time = $this->input->post('input_time');
        $location = $this->input->post('input_location');
        $status = $this->input->post('input-drop');
        $agenda = $this->input->post('input_agenda'); //agenda
        $attendee_id_list = $this->input->post('id_list');
        $attendee_id_list = rtrim($attendee_id_list, ' ');
        $attendee_id_list = explode(' ', $attendee_id_list);

        $date = date_format(date_create($date), 'Y-m-d');
        /*
        $this->setup_view("asdfasdf",array(
            "name" =>             $name,
            "recorder_id" =>      $recorder_id,
            "agenda" =>           $agenda,
            "dateTime" =>         $date.' '.$time,
            "location" =>         $location,
            "status" =>           $status,
            "attendee_id_list" => $attendee_id_list
            ));

        return;
        //*/

        $this->FMIS_Meeting->addMeeting(
            array(
                "name" => $name,
                "recorder_id" => $recorder_id,
                "agenda" => $agenda,
                "date" => $date,
                "time" => $time,
                "location" => $location,
                "status" => $status)
        );
        if(sizeof($attendee_id_list)>0)
        {
            $this->FMIS_Meeting->addMeetingAttendees($attendee_id_list);
        }
        $this->view();
    }

    public function remove($id){
        $this->load->model('FMIS_Meeting');
        $this->FMIS_Meeting->removeMeeting($id);
        $this->view();
    }
}

/* End of file pages.php */
/* Location: ./application/controllers/pages.php */